<template>
  <div id="app">
    <nav-header v-if="isLogin"></nav-header>
    <router-view v-if="routeState"></router-view>
  </div>
</template>

<script>
import NavHeader from "components/navheader/NavHeader";
import { mapState } from 'vuex';
export default {
  name: "App",
  provide () {
    return {
      reload: this.reload
    }
  },
  created () {
    sessionStorage.getItem('pc') && this.$store.replaceState(Object.assign(this.$store.state, JSON.parse(sessionStorage.getItem('pc'))))

    window.addEventListener('beforeunload', () => {
      sessionStorage.setItem('pc', JSON.stringify(this.$store.state))
    })
  },
  data () {
    return {
      routeState: true
    }
  },
  computed: {
    ...mapState(['user']),
    isLogin () {
      return this.$route.name !== 'login'
    }
  },
  methods: {
    reload () {
      this.routeState = false
      this.$nextTick(() => {
        this.routeState = true
      })
    }
  },
  components: {
    NavHeader
  }
};
</script>

<style>
#app{
}
</style>
 